package com.example.knowledgeget1.KnowtCommon.Repository;

import com.example.knowledgeget1.KnowtCommon.Entity.KnowStatus;
import com.example.knowledgeget1.KnowtCommon.Entity.StatusId;
import jakarta.transaction.Transactional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface KnowStatusRepository extends JpaRepository<KnowStatus, StatusId> {
    List<KnowStatus> findByIdIn(List<StatusId> collect);

    // 批量更新学习状态
    @Transactional
    @Modifying
    @Query("UPDATE KnowStatus ks SET ks.status = true WHERE ks.id.stuId = ?1 AND ks.id.knowId IN ?2")
    void batchUpdateLearnStatus(Long stuId, List<Long> knowIds);

    // 批量更新未学习状态
    @Transactional
    @Modifying
    @Query("UPDATE KnowStatus ks SET ks.status = false WHERE ks.id.stuId = ?1 AND ks.id.knowId IN ?2")
    void batchUpdateUnLearnStatus(Long stuId, List<Long> knowIds);

    // 根据knowId删除knowstatus实体
    @Transactional
    void deleteById_KnowId(Long knowId);
}
